import { MSG_REPLY_TEXT_MAP } from '@/common/message'
import TencentCloudChat from '@tencentcloud/chat'
import { MessageEncryptor } from '@/hooks/useMessageEncryptor.ts'

MessageEncryptor.IsEncry = true
// 计算展示的回复消息的内容
export const renderReplyContent = (name?: string, type?: TencentCloudChat.TYPES, content?: any, roomType?: TencentCloudChat.TYPES) => {
  switch (type) {
    case TencentCloudChat.TYPES.MSG_GRP_SYS_NOTICE:
    case TencentCloudChat.TYPES.MSG_TEXT: {
      let messageForShow = content.text || ''
      if (messageForShow.startsWith(MessageEncryptor.MessageEncryptorContentPrefix)) {
        messageForShow = MessageEncryptor.decrypt(messageForShow)
      }
      return roomType === TencentCloudChat.TYPES.CONV_GROUP ? `${name}:${messageForShow}` : messageForShow
    }
    case TencentCloudChat.TYPES.MSG_IMAGE: {
      return roomType === TencentCloudChat.TYPES.CONV_GROUP
        ? `${name}:${MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_IMAGE]}`
        : MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_IMAGE]
    }
    case TencentCloudChat.TYPES.MSG_FILE: {
      return roomType === TencentCloudChat.TYPES.CONV_GROUP
        ? `${name}:${MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_FILE]}`
        : MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_FILE]
    }
    case TencentCloudChat.TYPES.MSG_AUDIO: {
      return roomType === TencentCloudChat.TYPES.CONV_GROUP
        ? `${name}:${MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_AUDIO]}`
        : MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_AUDIO]
    }
    case TencentCloudChat.TYPES.MSG_VIDEO: {
      return roomType === TencentCloudChat.TYPES.CONV_GROUP
        ? `${name}:${MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_VIDEO]}`
        : MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_VIDEO]
    }
    case TencentCloudChat.TYPES.MSG_GRP_TIP: {
      return roomType === TencentCloudChat.TYPES.CONV_GROUP
        ? `${name}:${MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_GRP_TIP]}`
        : MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_GRP_TIP]
    }
    case TencentCloudChat.TYPES.MSG_MERGER: {
      return roomType === TencentCloudChat.TYPES.CONV_GROUP
        ? `${name}:${MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_MERGER]}`
        : MSG_REPLY_TEXT_MAP[TencentCloudChat.TYPES.MSG_MERGER]
    }
    default: {
      return ''
    }
  }
}
